package edu.xmut.yuepaibackend.controller;

import cn.hutool.core.map.MapUtil;
import edu.xmut.yuepaibackend.model.form.BlogPublishForm;
import edu.xmut.yuepaibackend.service.BlogService;
import edu.xmut.yuepaibackend.utils.R;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;

@RestController
@RequestMapping("/publish")
public class PublishController {

    @Resource
    private BlogService blogService;

    @PostMapping("/blog")
    public R publishBlog(@RequestBody BlogPublishForm blogPublishForm, HttpServletRequest request) {
        Long id = blogService.publish(blogPublishForm, request);
        HashMap<String, Long> data = MapUtil.of("id", id);
        return R.ok(data);
    }

}
